package com.oracle.sbdb.dao;

import java.io.IOException;
import java.io.InputStream;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

public class SessionFactory {
	private static class FactoryHolder {
		private static SqlSessionFactory INSTANCE = null;
		static{
			try {
				String resource = "com/oracle/sbdb/mybatis-config.xml";
				InputStream inputStream = Resources.getResourceAsStream(resource);
				INSTANCE = new SqlSessionFactoryBuilder().build(inputStream);
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}
	public static SqlSession getSession(){
		SqlSession session = null;
		synchronized(FactoryHolder.INSTANCE){
			if(FactoryHolder.INSTANCE != null){
				session = FactoryHolder.INSTANCE.openSession();
			}
		}
		return session;
	}
}
